from collections import OrderedDict

from django.conf import settings
from django.shortcuts import render
from goods.models import GoodsCategory, GoodsChannel, GoodsChannelGroup, SKU
from .models import *
# Create your views here.
from django.views import View

from .utils import get_categories


class IndexView(View):
    '''
    首页
    '''
    def get(self,request):
        """提供首页页面"""
        # 组织响应商品分类数据
        categories = get_categories()
        # 组织响应所有的广告数据
        contents = {}
        content_categories = ContentCategory.objects.all()
        for contents_category in content_categories:
            contents[contents_category.key] = contents_category.content_set.filter(status=True).order_by('sequence')


        context = {
            'categories':categories,
            'contents':contents
        }



        return render(request,'index.html',context)
